"use strict";

angular.module('app.dashboard').controller('socialCtrl', function($scope,cadbimHttpS,$timeout) {
		// $scope.allProject =
		//  [
  //         {
  //           "project_id":"221",
  //           "project":"项目一",
  //           "class"  :"active",
  //           "divClass":"tab-pane fade active in",
  //           "project_name":"灰心ui发的哈",
  //           // "p_img":"assets/img/img_share.jpg",
  //           // "p_progress":"25%",
  //           // "p_manager":"闵亚楠",
  //           // "label":"fjasf",
  //           // "account":"说明",
  //           // "p_teams":[{"img":"upload/img/26/t2.jpg"},{"img":"upload/img/26/t2.jpg"},{"img":"upload/img/26/t2.jpg"}],
  //           "miles" : [{"milestone_name":"项目起始","milestone_status":"active"},{"milestone_name":"里程碑2","milestone_status":"active"},{"milestone_name":"里程碑3","milestone_status":""},{"milestone_name":"里程碑4","milestone_status":""}],
  //           "menu": [{
  //                   "task_user":"田伟厚1",
  //                   "task_progress":"15%",
  //                   "list":[
  //                       {   "task_name":"BIM开发1",
  //                           "create_data"   :"2017-06-25",
  //                           "children":
  //                               [{
  //                                   "create_data":"2017-06-16",
  //                                   "task_children_name":"Follow your heart, but take your brain with you"
  //                               },
  //                                   {
  //                                       "create_data":"2017-06-06",
  //                                       "task_children_name":"Always remember that you are absolutely unique"
  //                                   },
  //                                   {
  //                                       "create_data":"2017-06-26",
  //                                       "task_children_name":"Always remember that you are absolutely unique"
  //                                   }]
  //                       },
  //                       {   "task_name":"BIM开发2",
  //                           "create_data"   :"2017-06-25",
  //                           "children":
  //                               [{
  //                                   "create_data":"2017-06-16",
  //                                   "task_children_name":"Follow your heart, but take your brain with you"
  //                               },
  //                                   {
  //                                       "create_data":"2017-06-06",
  //                                       "task_children_name":"Always remember that you are absolutely unique"
  //                                   },
  //                                   {
  //                                       "create_data":"2017-06-26",
  //                                       "task_children_name":"Always remember that you are absolutely unique"
  //                                   }]
  //                       }
  //                       ],
  //               }]
  //         },
  //         {
  //           "project_id":"225",
  //           "project":"项目二",
  //           "class"  :"",
  //           "divClass":"tab-pane fade",
  //           "project_name":"fgvdgsdeadgfdsa",
  //           // "p_img":"assets/img/project.jpg",
  //           // "p_progress":"25%",
  //           // "p_manager":"闵亚楠",
  //           // "label":"fjasf",
  //           // "account":"说明",
  //           // "p_teams":[{"img":"upload/img/26/t2.jpg"},{"img":"upload/img/26/t2.jpg"},{"img":"upload/img/26/t2.jpg"}],
  //           "miles" : [{"milestone_name":"项目起始","milestone_status":"active"},{"milestone_name":"里程碑2","milestone_status":"active"},{"milestone_name":"里程碑3","milestone_status":""},{"milestone_name":"里程碑4","milestone_status":""}],
  //           "menu": [{
  //                   "task_user":"田伟厚1",
  //                   "task_progress":"15%",
  //                   "list":[
  //                       {   "task_name":"BIM开发1",
  //                           "create_data"   :"2017-06-25",
  //                           "children":
  //                               [{
  //                                   "create_data":"2017-06-16",
  //                                   "task_children_name":"hahahhahah"
  //                               },
  //                                   {
  //                                       "create_data":"2017-06-06",
  //                                       "task_children_name":"军事老地方看过"
  //                                   },
  //                                   {
  //                                       "create_data":"2017-06-26",
  //                                       "task_children_name":"军事老地方看过"
  //                                   }]
  //                       }],
  //               }]
  //         }

  //     ];
    // 获取我参与的项目信息
    var getData = function(){
      cadbimHttpS.get_with_me('pro_with_me').then(function(response){
          
          // $scope.allProject = response;
          if (response != undefined) {
                // 处理数据
                takewith(response);
              }
         });
    } 
    getData();
        // 处理数据 绑定数据
    var takewith = function(res){          // 处理数据
          for (var i = 0; i < res.length; i++) {
            if (i == 0) {
               res[i].class = "active";
               res[i].divClass = "tab-pane fade active in";
            }else{
               res[i].class = "";
               res[i].divClass = "tab-pane fade";
            }
            res[i].project = "项目"+(i+1);
            //里程碑数据处理
            var arr = res[i].miles;
            for (var j = 0; j < arr.length; j++) {
               arr[j].step = j+1;
            }
          }
          $scope.allProject = res;
    }
    $scope.showall = function(id){
        $(".content_tab"+id).stop().fadeIn();
        $(".toggle_q"+id).children().removeClass('fa-plus');
        $(".toggle_q"+id).children().addClass('fa-minus');
    }
    $scope.hideall = function(id){
        $(".content_tab"+id).stop().fadeOut();
        $(".toggle_q"+id).children().removeClass('fa-minus');
        $(".toggle_q"+id).children().addClass('fa-plus');
    }
	$scope.MyTaskbar = function (index,event) {
		// 点击对应显示
		$(event.target).parents("header").next().fadeToggle();
		if ($(event.target).children().attr('class') == 'fa text-muted fa-plus'){
			$(event.target).children().removeClass('fa-plus');
			$(event.target).children().addClass('fa-minus');
		}else {
			$(event.target).children().removeClass('fa-minus');
			$(event.target).children().addClass('fa-plus');
		}
	};
	$timeout(function(){
        // 我的任务栏bootstrap插件
        $('.tree li.parent_li').find(' > ul > li').css({"display":"none"});
        $('.tree li:has(ul)').addClass('parent_li').find(' > span').attr('title', 'Collapse this branch');
        $('.tree li.parent_li > span').off('click').on('click', function (e) {
            var children = $(this).parent('li.parent_li').find(' > ul > li');
            if (children.is(":visible")) {
                children.hide('fast');
                $(this).attr('title', 'Expand this branch').find(' > i').addClass('icon-plus-sign').removeClass('icon-minus-sign');
            } else {
                children.show('fast');
                $(this).attr('title', 'Collapse this branch').find(' > i').addClass('icon-minus-sign').removeClass('icon-plus-sign');
            }
            e.stopPropagation();
        });
    },3000)



});



